<!--#include file="../nav/admin_top.php" -->
<div class="titleDiv">
	<div class="titleCaption">
		<span class="captionSpan">溯源管理 - 供应溯源</span>	</div>
</div>
<div style="margin:15px auto">
	搜索：
	<select id="status" class="textBox" style="margin-right:40px;">
		<option value="">-- 所有配送状态 --</option>
		<option value="0">计划中</option> 
		<option value="1">生产中</option> 
		<option value="2">已完成</option>
	</select> 
	<select id="senddate" class="textBox"  onChange="fnSearchDate()" style="margin-right:5px;">
		<option value="0" selected="selected">所有配送日期</option>
		<option value="1">今天</option> 
		<option value="2">本周</option> 
		<option value="3">本月</option> 
		<option value="">自定义时间段</option> 
	</select>
	<span id="s_date_div" style="display:none;margin:5px auto;">
		从 <input type="text" class="textBoxDate" id="b_date" value=""   maxlength="10" />
		<input id="b_date_slt" class="btnicon_calendar" type="button">
		到
		<input type="text" class="textBoxDate" id="e_date" value=""   maxlength="10" />
		<input id="e_date_slt" class="btnicon_calendar" type="button">
	</span>	
	
	<span style="margin-left:40px;">
		<input type="text" maxlength="12" id="keywords" class="searchs" /> 
		<input type="button"  onclick="fnSearchs()" value="查询"  />  	
	</span>
</div> 
<div id="grids"></div> 
<script type="text/javascript">
var url_list = '/admin_source_pro/index';
var url_modify = '/admin_source_pro/modify';
$().ready(function(){
	o2js.build('jscalendar');
	o2js.build('dates');
	fnSetSltDate('b_date','b_date_slt')
	fnSetSltDate('e_date','e_date_slt')
	$('#b_date').val(getWeekFirst(new Date()).eformat('yyyy-MM-dd'));
	$('#e_date').val(getWeekLast(new Date()).eformat('yyyy-MM-dd'));
	$('#b_date').val('');
	$('#e_date').val('');
	o2js.build('o2grid');
	showLoading();
	grids = new o2Grid({
		bind:'grids', 
		url:url_list,
		imgpath:'/misc/vendors/o2js/o2grid/image',
		cols:[
			{index:'id',mapping:'a.id', name:'序号', width:35,sortable:false, func:function(val,row_index,column_name,json,R){
				 return  '<span title="ID：'+json.id+'" >'+((R.page - 1)*R.rowNum + (row_index+1))+'</span>';
			}}, 
			{index:'code',mapping:'a.code', name:'配送批次编号', width:130,func:function(val,row_index,column_name,json,R){
					
					return '<a target="_blank" href="/admin_sendpi/view?id='+json.sendpi_id+'"   >'+val+'</a>';
				}
			},
			{index:'senddate',mapping:'a.senddate', name:'配送日期', width:80 
			}, 
			{index:'status',mapping:'a.status', name:'配送状态', width:70 ,func:function(val,row_index,column_name,json,R){
					if(val == '0'){
						return  '<span class=" ">计划中</span>';
					}else if(val == '1'){
						return  '<span class="red">生产中</span>';
					}else{
						return '<span class="green">已完成</span>';
					}
			}
			},
			{index:'vegenums',mapping:'vegenums',sortable:false, name:'蔬菜总数', width:70 
			}, 
			{index:'usernums',mapping:'usernums',sortable:false, name:'会员总数', width:70
			}, 
			{index:'state',mapping:'b.state',sortable:false, name:'溯源录入状态', width:320 ,func:function(val,row_index,column_name,json,R){
				var str = '';
				if(json.pro_flag == '0'){
					str += '<div class="noflag">供应溯源</div>';
				}else{
					str += '<div class="yesflag">供应溯源</div>';
				}
				if(json.make_flag == '0'){
					str += '<div class="noflag">生产溯源</div>';
				}else{
					str += '<div class="yesflag">生产溯源</div>';
				}
				if(json.send_flag == '0'){
					str += '<div class="noflag">配送溯源</div>';
				}else{
					str += '<div class="yesflag">配送溯源</div>';
				}
				return str;
			}
			}, 
			{index:'id',mapping:'a.id', name:'操作'	, width:100,sortable:false,func:function(val,row_index,column_name,json,R){
					var s = ' <a href="'+url_modify+'?id='+json.id+'" style="color: "  ><img src="/misc/images/edit.gif" />录入供应溯源</a>';
					return s;
				}
			}
		],
		endfunc:function(obj){
		}
	});
	fnSearchs();	 
	$('#keywords').keypress(function(e){
		if(e.keyCode==13||e.keyCode==10){
			fnSearchs();
		}
	});
});
function fnSearchs(){
	grids.setBaseParams({
		keywords:encodeURIComponent($('#keywords').val()),
		status:$('#status').val(),
		b_date:$('#b_date').val(),
		e_date:$('#e_date').val()
	}); 
	grids.load(1); 
}
/* 预定义日期 */
function fnSearchDate(){
	$('#s_date_div').hide();
	var date = new Date();
	switch($('#senddate').val()){
		case "0"://  
			$('#b_date').val('');
			$('#e_date').val('');
			break;
		case "1"://  
			$('#b_date').val(today());
			$('#e_date').val(today());
			break;
		case "2":// 
			var b = getWeekFirst(date).eformat('yyyy-MM-dd');
			var e = getWeekLast(date).eformat('yyyy-MM-dd'); 
			$('#b_date').val(b);
			$('#e_date').val(e);
			break;
		case "3"://本月
			var b = getMonthFirst(date).eformat('yyyy-MM-dd');
			var e = getMonthLast(date).eformat('yyyy-MM-dd'); 
			$('#b_date').val(b);
			$('#e_date').val(e);
			break;
		default:
			$('#s_date_div').show();
			break;
	}
}
</script>
<!--#include file="../nav/admin_bottom.php" -->